<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
<head>
<title>创建</title>
<script src="${contextPath}/resources/common/js/jquery.validate.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
<script src="<ls:templateResource item='/resources/plugins/My97DatePicker/WdatePicker.js'/>" type="text/javascript"></script>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/themes/default/default.css'/>" />
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.css'/>" />
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/kindeditor-min.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/lang/zh_CN.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.js'/>"></script>
<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet" />
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
<style>
.dailyLog table th, .dailyLog table td {
	padding: 10px 5px !important;
}

.dailyLog table td input {
	height: 28px;
	text-indent: 5px;
	outline: none;
}
</style>
</head>
<body>
	<form:form  action="${contextPath}/admin/task/loadTaskEstimate/${task.id}" id="form2" method="post">
		<input type="hidden" id="curPageNO" name="curPageNO" value="${curPageNO}" />
	    <div id="taskEstimatePage"></div>
	</form:form>
	<!-- 
	<c:if test="${not empty taskEstimateList}">
		<table border="0" align="center" class="${tableclass} " id="col2" style="padding: 5px; width: 100%">
			<thead>
				<tr class="sortable">
					<th style="width: 30px; text-align: center;">ID</th>
					<th>组员</th>
					<th style="min-width: 80px">日期</th>
					<th>工时</th>
					<th>剩余</th>
					<th style="min-width: 250px">日志</th>
					<th style="min-width: 30px">操作</th>
				</tr>
			</thead>
			<c:forEach items="${taskEstimateList}" var="te" varStatus="index">
				<tr class="data">
					<td style="width: 30px; text-align: center;">${index.count}</td>
					<td>${te.userName}</td>
					<td><fmt:formatDate value="${te.date}" pattern="yyyy-MM-dd" /></td>
					<td>${te.consumed}</td>
					<td>${te.leftHours}</td>
					<td>${te.work}</td>
					<th style="text-align: center; text-decoration: none; font-weight: normal;">
					<c:if test="${te.reviewed eq 0 }">
						<a href="javascript:deleteTaskEstimate(${te.id})">X</a>
					</c:if>
					</th>
				</tr>
			</c:forEach>
		</table>
	</c:if>
	 -->
	<form method="post" id="form1">
		<input id="id" name="id" value="${dailyLog.id}" type="hidden">
		<div align="center" class="dailyLog">
			<table border="0" align="center" class="${tableclass} " id="col1" style="padding: 5px; width: 100%">
				<thead>
					<tr class="sortable">
						<th style="width: 30px; text-align: center;">ID</th>
						<th>日期</th>
						<th>工时</th>
						<th>剩余</th>
						<th style="min-width: 250px">日志</th>
					</tr>
				</thead>
				<c:forEach begin="0" end="3" varStatus="index">
					<tr class="data">
						<td style="width: 30px; text-align: center;">${index.count}</td>
						<td><input readonly="readonly" name="wdate" class="Wdate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="width: 100px"></td>
						<td><input type="text" name="taskestimate" style="width: 50px;" /></td>
						<td><input type="text" name="leftHours" style="width: 50px;" /></td>
						<td><input type="text" name="remark" style="width: 400px;" /></td>
					</tr>
				</c:forEach>
				<tr>
					<td colspan="7">
						<div align="center">
							<input type="button" name="Submit" id="Submit" value="提交" />
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
	<script language="javascript">
		    $.validator.setDefaults({
		        submitHandler: function() {
		            alert("提交事件!");
		          }
		    });

    $(document).ready(function() {
   	 //查询分页数据
     sendData();
    	
	 //binding Submit
  	 $("#Submit").click(function(){
  		    var formData = [];
  		    var isBreak = false;
	  	    $(".data").each(function(){
	  	    var $this = $(this);
	  	    var date = $.trim($this.find("input[name='wdate']").val());
	  	  	var taskestimate = $.trim($this.find("input[name='taskestimate']").val());
	  		var leftHours = $.trim($this.find("input[name='leftHours']").val());
	  		var remark = $.trim($this.find("input[name='remark']").val());
	  		var total= 0;
	  		if(date){
	  			total ++;
	  		}
	 		if(taskestimate && taskestimate > 0){
	  			total ++;
	  		}
	 		if(leftHours){
	  			total ++;
	  		}
	 		
	 		if(remark){
	  			total ++;
	  		}
	 		
	  		if(total == 4){
		  		var obj = {"date":date, "taskestimate": taskestimate, "leftHours":leftHours, "remark": remark};
		  		formData.push(obj);
	  		}else if(total != 0){
	  			layer.msg("数据有误:工时必须要大于0; 每一行请填写完整.");
	  			isBreak = true;
	  			return true;
	  		}
	  	  });
	  	  
	  	  if(!isBreak && formData.length == 0){
	  			layer.msg("数据有误:工时必须要大于0; 每一行请填写完整.");
	  			return true; 
	  	  }
	  	
	  	var data = JSON.stringify(formData);
  	 if(!isBreak){
  	 var formData = $("#form1").serialize();
  	   $.ajax({
         type: 'post', // 提交方式 get/post
         url:  "${contextPath}/admin/task/saveTaskEstimate/${task.id}", // 需要提交的 url
         data: {"taskEstimateDto": data},
         dataType : 'json', 
         error: function(jqXHR, textStatus, errorThrown) {
  	 		 layer.alert("保存失败:必须选中目标;并且工时要大于0.");
  		},
         success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
             // 此处可对 data 作相关处理
             if("success" == data){
               layer.msg("保存成功");
               closeDialog();
             }else if("fail" == data){
           	   layer.msg("保存失败:必须选中目标;并且工时要大于0.");
             }if("noIn" === data){
           	  layer.msg("目前不在项目里");
			 }if("statusError" == data){
				 layer.msg("目标状态必须要是启动或者延误状态");
             }else{
           	  layer.msg("保存失败:必须选中目标;并且工时要大于0.");
             }
           
         }
     });
     return false; // 阻止表单自动提交事件
  	}; 
  	});
});
    
    //加载日志
	function sendData(){
		var formData = $("#form2").serialize();
	     $.ajax({
	    		url:"${contextPath}/admin/task/loadTaskEstimate/${task.id}", 
	    		type:'post', 
	    		data:formData,
	    		async : true, //默认为true 异步   
	    		error: function(jqXHR, textStatus, errorThrown) {
	    		 //  alert("系统异常" + " jqXHR= " + jqXHR + ", textStatus = " + textStatus + ",errorThrown =  " + errorThrown);
	    		},
	    		success:function(result){
	    		   $("#taskEstimatePage").html(result);
	    		}
	    	});
    }
	
    function pager(curPageNO){
        document.getElementById("curPageNO").value=curPageNO;
        sendData();
    }
    
	function closeDialog(){
		var index = parent.layer.getFrameIndex("taskEstimate"); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭   
		if(parent.sendData){
			parent.sendData();//异步
		}else{
			//parent.location.reload(); //不要刷新页面
		}
	}
	

</script>
</body>
</html>
